<template>
  <div class="risk">
    <eagle-tab-page-list
      ref="eaglePageList"
      @initList="bindData"
      @initActive="initActive"
      :params="params"
      url="/DangerTemplate/GetPageData"
    >
      <eagle-cell
        class="card"
        v-for="(dataItem, index) in list"
        :key="index"
        @click="goDetail(dataItem)"
      >
        <div class="f15">{{ dataItem.Title }}</div>
        <div class="f666">{{ dataItem.Remarks || "暂无描述" }}</div>
        <van-row type="flex" justify="space-between" v-if="active == 2">
          <div @click.stop="edit(dataItem)">
            <img
              class="icon"
              src="@/assets/Images/AppIcon/icon_list_edit.png"
              alt=""
            />
            <span>修改名称</span>
          </div>
          <div @click.stop="handleDelete(dataItem)">
            <img
              class="icon"
              src="@/assets/Images/AppIcon/icon_delete.png"
              alt=""
            />
            <span>删除</span>
          </div>
        </van-row>
      </eagle-cell>
    </eagle-tab-page-list>
    <van-dialog
      v-model="show"
      title="修改检查表名称"
      @confirm="handleConfirm()"
      show-cancel-button
    >
      <van-form>
        <van-field
          clickable
          name="Title"
          v-model="form.Title"
          placeholder="请输入"
        />
      </van-form>
    </van-dialog>
  </div>
</template>

<script>
import { editName, dlete } from "@/api/dangerTemplate";
import { Dialog } from "vant";
export default {
  data() {
    return {
      show: false,
      active: 0,
      params: [
        {
          title: "部门检查表",
          dataType: "CompanyCMPLList",
          limit: 20,
        },
        {
          title: "公共检查表",
          dataType: "SysCMPLList",
          limit: 20,
        },
        {
          title: "我的检查表",
          dataType: "UserList",
          limit: 20,
        },
      ],
      list: [],
      form: {},
    };
  },
  methods: {
    bindData(list) {
      this.list = list;
    },
    initActive(active) {
      this.active = active;
    },
    edit(obj) {
      this.form.ID = obj.ID;
      this.form.TemplateType = obj.TemplateType;
      this.form.CompanyCode = obj.CompanyCode;
      this.form.Title = obj.Title;
      this.form.OPCode = obj.OPCode;
      this.show = true;
    },
    handleConfirm() {
      editName(this.form).then((res) => {
        this.$toast.success("编辑成功！");
        setTimeout(() => {
          this.$refs.eaglePageList.getList();
        }, 1000);
      });
    },
    handleDelete(item) {
      Dialog.confirm({
        title: "询问",
        message: "确定要删除该条记录吗?",
      })
        .then(() => {
          dlete({ id: item.ID }).then((res) => {
            this.$toast.success("删除成功！");
            setTimeout(() => {
              this.$refs.eaglePageList.getList();
            }, 1000);
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    goDetail(item) {
      this.$router.push({
        path: "/OtherDanger/DangerTemplateDetail",
        query: { tCode: item.TCode },
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>
